home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / ripply-anim.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  4.4 KB  |  129 lines

  1. ; "Rippling Image" animation generator (ripply-anim.scm)
  2. ; Adam D. Moss (adam@foxbox.org)
  3. ; 97/05/18
  4. ;
  5. ; Designed to be used in conjunction with a plugin capable
  6. ; of saving animations (i.e. the GIF plugin).
  7. ;
  8.  
  9. (define (copy-layer-ripple dest-image dest-drawable source-image source-drawable)
  10.   (gimp-selection-all dest-image)
  11.   (gimp-edit-clear dest-drawable)
  12.   (gimp-selection-none dest-image)
  13.   (gimp-selection-all source-image)
  14.   (gimp-edit-copy source-drawable)
  15.   (gimp-selection-none source-image)
  16.       (let ((floating-sel (car (gimp-edit-paste dest-drawable FALSE))))
  17.     (gimp-floating-sel-anchor floating-sel)))
  18.  
  19. (define (script-fu-ripply-anim img drawable displacement num-frames edge-type)
  20.   (let* ((width (car (gimp-drawable-width drawable)))
  21.      (height (car (gimp-drawable-height drawable)))
  22.      (ripple-image (car (gimp-image-new width height GRAY)))
  23.      (ripple-layer (car (gimp-layer-new ripple-image width height GRAY-IMAGE "Ripple Texture" 100 NORMAL-MODE)))
  24.      (rippletiled-ret)
  25.      (rippletiled-image)
  26.      (rippletiled-layer)
  27.      (remaining-frames)
  28.      (xpos)
  29.      (ypos)
  30.      (xoffset)
  31.      (yoffset)
  32.      )
  33.  
  34.  ; this script generates its own displacement map
  35.  
  36.     (gimp-context-push)
  37.  
  38.     (gimp-image-undo-disable ripple-image)
  39.     (gimp-context-set-background '(127 127 127) )
  40.     (gimp-image-add-layer ripple-image ripple-layer 0)
  41.     (gimp-edit-fill ripple-layer BACKGROUND-FILL)
  42.     (plug-in-noisify 1 ripple-image ripple-layer FALSE 1.0 1.0 1.0 0.0)
  43.     ; tile noise
  44.     (set! rippletiled-ret (plug-in-tile 1 ripple-image ripple-layer (* width 3) (* height 3) TRUE))
  45.     (gimp-image-undo-enable ripple-image)
  46.     (gimp-image-delete ripple-image)
  47.  
  48.     (set! rippletiled-image (car rippletiled-ret))
  49.     (set! rippletiled-layer (cadr rippletiled-ret))
  50.     (gimp-image-undo-disable rippletiled-image)
  51.  
  52.     ; process tiled noise into usable displacement map
  53.     (plug-in-gauss-iir 1 rippletiled-image rippletiled-layer 35 TRUE TRUE)
  54.     (gimp-equalize rippletiled-layer TRUE)
  55.     (plug-in-gauss-rle 1 rippletiled-image rippletiled-layer 5 TRUE TRUE)
  56.     (gimp-equalize rippletiled-layer TRUE)
  57.  
  58.     ; displacement map is now in rippletiled-layer of rippletiled-image
  59.  
  60.     ; loop through the desired frames
  61.  
  62.     (set! remaining-frames num-frames)
  63.     (set! xpos (/ width 2))
  64.     (set! ypos (/ height 2))
  65.     (set! xoffset (/ width num-frames))
  66.     (set! yoffset (/ height num-frames))
  67.  
  68.     (let* (
  69.           (out-imagestack (car (gimp-image-new width height RGB)))
  70.           (dup-image)
  71.           (dup-layer)
  72.           (layer-name)
  73.           (this-layer)
  74.           )
  75.  
  76.       (gimp-image-undo-disable out-imagestack)
  77.       
  78.       (while (> remaining-frames 0)
  79.          (set! dup-image (car (gimp-image-duplicate rippletiled-image)))
  80.          (gimp-image-undo-disable dup-image)
  81.          (gimp-image-crop dup-image width height xpos ypos)
  82.          
  83.          (set! layer-name (string-append "Frame "
  84.             (number->string (- num-frames remaining-frames) 10)
  85.             " (replace)"))
  86.          (set! this-layer (car (gimp-layer-new out-imagestack
  87.                            width height RGB
  88.                            layer-name 100 NORMAL-MODE)))
  89.          (gimp-image-add-layer out-imagestack this-layer 0)
  90.          
  91.          (copy-layer-ripple out-imagestack this-layer img drawable)
  92.          
  93.          (set! dup-layer (car (gimp-image-get-active-layer dup-image)))
  94.          (plug-in-displace 1 out-imagestack this-layer
  95.                    displacement displacement
  96.                    TRUE TRUE dup-layer dup-layer edge-type)
  97.          
  98.          (gimp-image-undo-enable dup-image)
  99.          (gimp-image-delete dup-image)
  100.          
  101.          (set! remaining-frames (- remaining-frames 1))
  102.          (set! xpos (+ xoffset xpos))
  103.          (set! ypos (+ yoffset ypos)))
  104.       
  105.       (gimp-image-undo-enable rippletiled-image)
  106.       (gimp-image-delete rippletiled-image)
  107.       (gimp-image-undo-enable out-imagestack)
  108.       (gimp-display-new out-imagestack))
  109.  
  110.     (gimp-context-pop)))
  111.  
  112. (script-fu-register "script-fu-ripply-anim"
  113.             _"_Rippling..."
  114.             "Ripple any image by creating animation frames as layers"
  115.             "Adam D. Moss (adam@foxbox.org)"
  116.             "Adam D. Moss"
  117.             "1997"
  118.             "RGB* GRAY*"
  119.             SF-IMAGE       "Image to animage"    0
  120.             SF-DRAWABLE    "Drawable to animate" 0
  121.             SF-ADJUSTMENT _"Rippling strength"   '(3 0 256 1 10 1 0)
  122.             SF-ADJUSTMENT _"Number of frames"    '(15 0 256 1 10 0 1)
  123.             SF-OPTION     _"Edge behaviour"      '(_"Wrap"
  124.                                _"Smear"
  125.                                _"Black"))
  126.  
  127. (script-fu-menu-register "script-fu-ripply-anim"
  128.              _"<Image>/Script-Fu/Animators")
  129.